package xyz.scootaloo.mono.base.util

import java.lang.management.ManagementFactory

/**
 * 开发工具
 *
 * [isDebugging] 一个有用的属性, 用来查看当前程序是否处于debug模式
 *
 * [参考](https://www.zhihu.com/question/30673515/answer/49146504)
 *
 * @author flutterdash@qq.com
 * @since 2021/7/29 6:39
 */
object DevUtil {
    val isDebugging: Boolean = isEnableDebug()

    private fun isEnableDebug(): Boolean {
        val args = ManagementFactory.getRuntimeMXBean()?.inputArguments
        if (args != null) {
            for (arg in args) {
                if (arg.startsWith("-Xrunjdwp") || arg.startsWith("-agentlib:jdwp"))
                    return true
            }
        }
        return false
    }
}
